 library ieee;


-- Commonly imported packages:

	-- STD_LOGIC and STD_LOGIC_VECTOR types, and relevant functions
	use ieee.std_logic_1164.all;

	-- SIGNED and UNSIGNED types, and relevant functions
	use ieee.numeric_std.all;

	-- Basic sequential functions and concurrent procedures
	use ieee.VITAL_Primitives.all;


use IEEE.STD_LOGIC_UNSIGNED.ALL;



entity mem_gen is
	port(
		DEC_CLK	: in std_logic;   --input_CLK	
		DEC_LLC	: out std_logic;   --input_CLK
		DEC_D		: out std_logic_vector(7 downto 0)
		);
end entity;

-- Library Clause(s) (optional)
-- Use Clause(s) (optional)

architecture rtl of mem_gen is

	-- Declarations (optional)
constant max_pix:integer := 1728;
constant pix_eav:integer := 284;
shared variable pix_num: integer range 0 to max_pix;
shared variable line_num: integer range 0 to 625;
begin

test_generator:
process(DEC_CLK)
variable num_line:integer range 0 to 312;
variable v:std_logic;
constant v1:std_logic_vector:="10000000";
constant v2:std_logic_vector:="10100000";
constant v3:std_logic_vector:="10010000";
constant v4:std_logic_vector:="10110000";
begin
	if(falling_edge(DEC_CLK))then
	  if(pix_num<1727)then
		pix_num:= pix_num + 1;
		else
		pix_num:=0;
		end if;
		if(pix_num = 0 or pix_num = (0+pix_eav))then
			DEC_D <= "11111111";
		elsif(pix_num = 1 or pix_num = 2 or pix_num = (1+pix_eav) or pix_num = (2+pix_eav))then
			DEC_D <= "00000000";
		elsif(pix_num = 3)then
			if(num_line <311)then
				if num_line =3 then
					v:= '0';
				end if;
		   num_line := num_line + 1;
			else
			v:= '1';
			num_line := 0;
			end if;
			
			if(v = '1')then
			DEC_D<=v3;
			else
			DEC_D<=v4;
			end if;
			
		elsif(pix_num = 3+284)then
			if(v = '1')then
			DEC_D<=v1;
			else
			DEC_D<=v2;
			end if;
		elsif(std_logic_vector(to_unsigned(pix_num,1))(0) = '0')then --CbCr channel
						
				if(pix_num<160)then
					DEC_D <= "10000000";
				else
					DEC_D <= "01111101";
				end if;	
		elsif(std_logic_vector(to_unsigned(pix_num,1))(0) = '1')then --Y channel
			/*if(num_line<120)then*/
				if(pix_num<160)then
					DEC_D <= "00010000";
				else
					DEC_D <= "01111101";
				end if;
			/*else
				if(pix_num<160)then
					DEC_D <= "01010101";	
				else
					DEC_D <= "00010100";
				end if;		
			end if;*/	
							
		end if;
	end if;
end process;


DEC_LLC <= DEC_CLK;

end rtl;